<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="编号:" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入昵称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态:" prop="status">
        <el-select
          v-model="queryParams.status"
          clearable
          placeholder="请选择"
        >
          <el-option
            label="初始"
            value="INIT"
          />
          <el-option
            label="完成"
            value="COMPLETE"
          />
          <el-option
            label="失败"
            value="ERROR"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易时间:" prop="createTime">
        <el-date-picker
          v-model="queryParams.createTime"
          type="daterange"
          clearable
          placeholder="日期区间选择"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    
    <el-table v-loading="loading" :data="walletMarketList">
      <el-table-column label="编号" align="center" prop="id" width="180"/>
      <el-table-column label="昵称" align="center" prop="nickName"/>
      <el-table-column label="类型" align="center" prop="type"/>
      <el-table-column label="兑换项" align="center" prop="fromPrice"/>
      <el-table-column label="承兑项" align="center" prop="toPrice"/>
      <el-table-column label="单价" align="center" prop="unitPrice"/>
      <el-table-column label="交易后余额" align="center" prop="balance"/>
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag type="success" effect="dark" v-if="scope.row.status == '完成'">
            {{ scope.row.status }}
          </el-tag>
          <el-tag type="info" effect="dark" v-else-if="scope.row.status == '初始'">
            {{ scope.row.status }}
          </el-tag>
          <el-tag type="danger" effect="dark" v-else>
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="交易时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="successTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.successTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.current"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="WalletMarket">
  import {listWalletExchange} from "@/api/boot/walletExchange.js";
  
  const {proxy} = getCurrentInstance();
  
  const walletMarketList = ref([]);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  
  const data = reactive({
    form: {},
    queryParams: {
      current: 1,
      size: 10,
      types:['USDT_ETH', 'ETH_USDT'],
    },
    rules: {}
  });
  
  const {queryParams, form, rules} = toRefs(data);
  
  /** 查询兑换列表 */
  function getList() {
    loading.value = true;
    listWalletExchange(queryParams.value).then(response => {
      walletMarketList.value = response.data.records;
      total.value = response.data.total;
      loading.value = false;
    });
  }
  
  // 表单重置
  function reset() {
    form.value = {
      id: null,
      type: null,
      channel: null,
      amount: null,
      balance: null,
      duration: null,
      status: null,
      positionStatus: null,
      startTime: null,
      startPrice: null,
      endTime: null,
      endPrice: null,
      lossOrGain: null,
      userNo: null
    };
    proxy.resetForm("walletMarketRef");
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.current = 1;
    getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
  
  
  getList();
</script>
